//index.js
const app = getApp()
Page({
  data: {
    userInfo: {},
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    tabArr: {
      curHdIndex: 0,
      curBdIndex: 0
    },
    tasks:[
      { id: 1, name: '墨盒修复',date:'2018-12-18', checked: 'true'},
      { id: 2, name: '卡纸故障',date: '2018-12-18', checked: 'true'}
    ],
    alltasks: [
      { id: 1, name: '墨盒修复', date: '2018-12-18', checked: 'true',turntask: 'false'},
      { id: 2, name: '卡纸故障', date: '2018-12-18', checked: 'true',turntask: 'true'},
      { id: 3, name: '故障报错', date: '2018-12-18', checked: 'true' },
      { id: 4, name: '预警信息', date: '2018-12-18', checked: 'true' }
    ]
  },

  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  // 获取头像
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  // tab菜单切换
  tab: function (e) {
    var dataId = e.currentTarget.id;
    var obj = {};
    obj.curHdIndex = dataId;
    obj.curBdIndex = dataId;
    this.setData({
      tabArr: obj
    })
  },
  // 跳转详情页面
  goInfo: function (e) {
    wx.navigateTo({
      url: '/pages/info/info?taskname=' + e.currentTarget.id,
    })
  },
  // 跳转转单页面
  goTurn: function (e) {
    wx.navigateTo({
      url: '/pages/turntask/turntask?taskname=' + e.currentTarget.id,
    })
  },
  // 跳转个人中心
  goHome: function () {
    wx.switchTab({
      url: '/pages/home/home'
    })
  }
})